﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NHibernate.Cfg;

namespace Lincolnwood.Foundation.Common.Data.NHibernate
{
    public abstract class NHibernateUnitOfWork : IUnitOfWork
    {
        private Configuration _configuration;

        public NHibernateUnitOfWork()
        {
            Helper = new NHibernateHelper();

        }

        public NHibernateUnitOfWork(Configuration configuration) : this()
        {
            _configuration = configuration;
            Session = Helper.OpenSession(_configuration);
        }

        public ISession Session
        {
            get;
            protected set;
        }

        protected NHibernateHelper Helper
        {
            get;
            private set;
        }

        public virtual void Flush()
        {
            Session.Flush();            
        }

        public void Close()
        {
            Session.Close();
        }

        public void Dispose()
        {
            Session.Dispose();
        }

        public abstract Configuration AddConfiguration(Configuration config);
      
    }
}
